package com.xiao.community.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xiao.community.entity.QianUserEntity;
import com.xiao.community.service.QianUserService;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.R;



/**
 * 
 *
 * @author 韩国涛
 * @email 18862701405@gmail.com
 * @date 2021-09-10 15:22:54
 */
@RestController
@RequestMapping("community/qianuser")
public class QianUserController {
    @Autowired
    private QianUserService qianUserService;

    @RequestMapping("login")
    public R login(@RequestBody QianUserEntity qianUserEntity){
        QianUserEntity qian=qianUserService.login(qianUserEntity);
        if (qian !=null){
            return R.ok().put("user",qian);
        }else {
            return R.error("登录失败，请重试");
        }

    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = qianUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    public R info(@PathVariable("userId") Integer userId){
		QianUserEntity qianUser = qianUserService.getById(userId);

        return R.ok().put("qianUser", qianUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody QianUserEntity qianUser){
		qianUserService.save(qianUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody QianUserEntity qianUser){
		qianUserService.updateById(qianUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] userIds){
		qianUserService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
